package com.loyal.loyalerp.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.loyal.loyalerp.basedata.company.mapper.GyCompanyMapper;
import com.loyal.loyalerp.basedata.company.model.GyCompany;
import com.loyal.loyalerp.humenresource.role.mapper.GyRoleMapper;
import com.loyal.loyalerp.humenresource.role.model.GyRole;
import com.loyal.loyalerp.mapper.GyUserMapper;
import com.loyal.loyalerp.model.GyUser;

@Controller
public class UserRoleAPI {

	@Autowired
	private GyCompanyMapper companyMapper;
	@Autowired
	private GyRoleMapper roleMapper;
	@Autowired
	private GyUserMapper userMapper;
	
	@RequestMapping("/editUserRole")
	public String toEditPage() {
		return "userrole";
	}
	
	@RequestMapping("/addRoleDialog")
	public String addRoleDialog(HttpServletRequest request) {
		HttpSession session = request.getSession();
		List<GyCompany> companyList = new ArrayList<GyCompany>();
		List<GyRole> roleList = new ArrayList<GyRole>();
		List<GyUser> userList = new ArrayList<GyUser>();
		companyList = companyMapper.companyList();
		roleList = roleMapper.alllistRole();
		userList = userMapper.selectAllEmploy();
		session.setAttribute("companyList", companyList);
		session.setAttribute("roleList", roleList);
		session.setAttribute("userList", userList);
		return "addroledialog";
	}
	
	@RequestMapping("/editRoleDialog")
	public String editRoleDialog(HttpServletRequest request) {
		System.out.println("进入了editRoleDialog");
		HttpSession session = request.getSession();
		List<GyRole> roleList = new ArrayList<GyRole>();
		roleList = roleMapper.alllistRole();
		session.setAttribute("roleList", roleList);
		return "editroledialog";
	}
}
